﻿using ArticleandSiteData;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace SplitViewOptions.BusinessControl
{
    public sealed partial class SharePicUserControl : UserControl
    {
        public SharePicUserControl()
        {
            this.InitializeComponent();
            this.Loaded += SharePicUserControl_Loaded;
        }

        private  async void SharePicUserControl_Loaded(object sender, RoutedEventArgs e)
        {
            PicInfoRootobject users = await BmobWebsiteData.GetLists<PicInfoRootobject>("https://api.bmob.cn/1/classes/sharepictable?order=-updatedAt");
            List<PicInfo> listresults = new List<PicInfo>();
            foreach(var a in users.results)
            {
                string str = a.pictags;
                string[] sp = { "，", ",", ";" };
                string[] result=  str.Split(sp,StringSplitOptions.RemoveEmptyEntries);
                a.tags = result;
                listresults.Add(a);
            }
            usersg.ItemsSource = listresults;
        }

        private void Border_Tapped(object sender, TappedRoutedEventArgs e)
        {
            try
            {
                Border tin = sender as Border;
                if (tin != null)
                {
                    PicInfo info = tin.DataContext as PicInfo;
                    if (info != null && string.IsNullOrEmpty(info.weburl))
                    {
                        return;
                    }

                    if (info != null)
                    {
                        App.Currenturl = new Uri(info.weburl, UriKind.RelativeOrAbsolute);
                    }
                }
                App.Mainframe.Navigate(typeof(HomePage));
            }
            catch (Exception ex)
            {
            }
        }
    }
    public class PicInfoRootobject
    {
        public PicInfo[] results { get; set; }
    }
    public class PicInfo
    {
        public string lookdownnumber { set; get; }
        public string supportnumber { set; get; }
        public string picfollowlist { set; get; }
        public string shareusername { set; get; }
        public string pictags { set; get; }
        public string pictitle { set; get; }      
        public string weburl { set; get; }
        public string picurl { set; get; }
        public string createtime { set; get; }
        public string updatedAt { set; get; }
        public string objectid { set; get; }

        public string[] tags { set; get; }
    }

}
